<script type="text/javascript">
var firefox = false;

if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
 var ffversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (ffversion>=1)
 {
     firefox = true;
 } 
}

function isMouseLeaveOrEnter(e, handler)
{    
    if (e.type != 'mouseout' && e.type != 'mouseover') return false;
    var reltg = e.relatedTarget ? e.relatedTarget :
    e.type == 'mouseout' ? e.toElement : e.fromElement;
    while (reltg && reltg != handler) reltg = reltg.parentNode;
    return (reltg != handler);
}
</script>
<?php
/* echo $this->navigation()
  ->menu()
  ->setContainer($this->navigation)
  ->setPartial(null)
  ->render(); */
?>

<ul class="navigation">
  <?php
  $content = "";
  $pre_main_content = "";
  $submenu_class = "";
  $flag = true;
  foreach ($this->navigation as $item):
    $target = isset($item->target)? $item->target: NULL;
    if ($item->route == NULL) {
      $item->route = 'default';
    }
    else if ($flag && $item->label == 'Home') {
      $item->route = 'home';
      $flag = false;
    }
    // Get Dropped Menu
    $droppedMenu = "droppedmenu_". $item->id;
    $mainMenu = "mainmenu_". $item->id;
    if (!$item->submenu):
      if ($content) {
        $submenu = "<ol class='servicesdropped " . $submenu_class . "_dropped' id='droppedmenu_". $item->id . "'>" . $content . "
                    </ol>
                ";  
           // Load all submenu id
        $submenu .= "
            <script type=\"text/javascript\">
                window.addEvent('domready',function(){
                  //$$('.{$submenu_class}').addEvent('mouseover',function(event){
                  $$('#{$mainMenu}').addEvent('mouseover',function(event){
                      if(firefox == false)
                      {
                          if(isMouseLeaveOrEnter(event, this))
                          {                            
                            $$('#{$droppedMenu}').show();
                        }
                    }
                    else 
                    {
                        $$('#{$droppedMenu}').show();
                    }
                  }).addEvent('mouseout',function(event){
                      if(firefox == false)
                      {
                          if(isMouseLeaveOrEnter(event, this))
                          {
                            $$('#{$droppedMenu}').hide();
                        }
                    }
                    else 
                    {
                        $$('#{$droppedMenu}').hide();
                    }
                  });
                });
                </script>
                ";
        $content = "";
        //echo $submenu;
        $pre_main_content = "<li  class='{$submenu_class} downservices' id='". $mainMenu ."'>"
                . $pre_main_content
                . $submenu
                . "</li>";
      } else {
        if ($pre_main_content) {

          $pre_main_content = "<li  class='{$submenu_class}'>"
                  . $pre_main_content
                  . "</li>";
        }
      }
      echo $pre_main_content;
      $main_item = $item->class;
      $submenu_class = $main_item; //"<div class='".$item->class."_dropped'>";
  ?>
  <?php
      if ($item->uri) {
        $str_format = '<a title="%s" class="menu_core_main" href="%s" target="%s">%s</a>';
        $pre_main_content = sprintf($str_format, $this->translate($item->label), $item->uri, $target, $this->translate($item->label));
      } else {
        $pre_main_content = $this->htmlLink(array('route' => $item->route, 'module' => $item->module,
                    'controller' => $item->controller, 'action' => $item->action,
                        ), $this->translate($item->label) . $item->uri, array('class' => 'menu_core_main','target'=>$target, 'title' => ''));
      }
  ?>
  <?php
      else:
        if (@$item->uri) {
          $format = '<a title="%s" class="menu_core_main core_main_home" target="%s" href="%s">%s</a>';
          $string = sprintf($format, $this->translate($item->label),$target, $item->uri,  $this->translate($item->label));
        } else {
          $string = $this->htmlLink(array('route' => $item->route, 'module' => $item->module,
                      'controller' => $item->controller, 'action' => $item->action,
                          ), $this->translate($item->label), array('class' => 'menu_core_main core_main_home','target'=>$target, 'title' => ''));
        }
        $content .= "<li>"
                . $string
                . "</li>";
  ?>
  <?php endif; ?>
  <?php
        endforeach;
        if ($content) {
          $submenu = "<ol class='servicesdropped " . $submenu_class . "_dropped' id='droppedmenu_". $item->id . "'>" . $content . "
                    </ol>
                ";
          $submenu .= "
                <script type='text/javascript'>
                window.addEvent('domready',function(){                    
                  //$$('.{$submenu_class}').addEvent('mouseover',function(event){
                  $$('#{$mainMenu}').addEvent('mouseover',function(event){
                  if(firefox == false)
                      {                                         
                          if(isMouseLeaveOrEnter(event, this))
                          {                                        
                        
                        $$('#{$droppedMenu}').show();
                        }
                    }
                    else 
                    {
                         $$('#{$droppedMenu}').show();
                    }
                  }).addEvent('mouseout',function(){
                  if(firefox == false)
                  {
                  if(isMouseLeaveOrEnter(event, this))
                  {                     
                    $$('#{$droppedMenu}').hide();
                    
                    }
                    }
                    else 
                    {
                     $$('#{$droppedMenu}').hide();
                    }
                  });
                });
                </script>
                ";
          $content = "";
          //echo $submenu;
          $pre_main_content = "<li  class='{$submenu_class} downservices' id='". $mainMenu ."'>"
                  . $pre_main_content
                  . $submenu
                  . "</li>";
        } else {
          if ($pre_main_content) {

            $pre_main_content = "<li  class='{$submenu_class}'>"
                    . $pre_main_content
                    . "</li>";
          }
        }
        echo $pre_main_content;
  ?>
</ul>
<script type="text/javascript">
  window.addEvent('domready', function() {
    $$('.downservices > .menu_core_main').each(
     function(e,i){
       if(e.setAttribute){
         //e.setAttribute('href', 'javascript:void(0);');
         //e.setAttribute('target', '');
       }
     })
  });
</script>